{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "private_outputs": true,
      "provenance": [],
      "gpuType": "T4",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/greengerong/awesome-llm/blob/main/colab/facechain_deploy_demo_%E8%AF%81%E4%BB%B6%E7%85%A7.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "Requirements:\n",
        "- GPU Mem Usage: 19G\n",
        "- Disk Usage: About 50G"
      ],
      "metadata": {
        "id": "AzOycrSUkK-0"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Get facechain source code from GitHub"
      ],
      "metadata": {
        "id": "8yQEWTkekIx9"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "!GIT_LFS_SKIP_SMUDGE=1 git clone https://github.com/modelscope/facechain.git --depth 1"
      ],
      "metadata": {
        "id": "WK_uDw0NkHTP"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Installation requirements\n",
        "- Note that you can ignore warning on dependencies conflicts at the end\n",
        "- You may use conda virtual env to avoid warning info."
      ],
      "metadata": {
        "id": "jUWWSGDG1ZGK"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "!pip3 install -r facechain/requirements.txt"
      ],
      "metadata": {
        "id": "QrwRDBipxKZw"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Check environment informaiton"
      ],
      "metadata": {
        "id": "0miaB1nC2VrA"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "!nvidia-smi\n",
        "!pip3 show torch\n",
        "\n",
        "# Note that this setup is verified on (cuda 12.0, torch2.0.1+cu118, Nvidia-A100 40G)"
      ],
      "metadata": {
        "id": "uvNE0kRxyI4q"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [],
      "metadata": {
        "id": "klba298h2bbu"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Installing mmcv-full\n",
        "- Several of the underlying models depend on mmcv-full, which could be tricky to install since it is environment-dependent, you may refer to [mmcv's official documentation](https://mmcv.readthedocs.io/zh_CN/latest/get_started/installation.html) for more details..\n",
        "- A prebuilt package is provided here for convenience, and was verified on (cuda 12.0, torch2.0.1+cu118, Nvidia-A100 40G)\n",
        "- If the prebuilt package does not work on your env setup, please use the alternative installation as suggested by [mmcv's official documentation](https://mmcv.readthedocs.io/zh_CN/latest/get_started/)"
      ],
      "metadata": {
        "id": "ciSxxSzI4l_u"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# use prebuilt mmcv-full package provided by ModelScope (verified on cuda 12.0, torch2.0.1+cu118, Nvidia-A100 40G)\n",
        "!pip3 install https://modelscope.oss-cn-beijing.aliyuncs.com/packages/mmcv/mmcv_full-1.7.0-cp310-cp310-linux_x86_64.whl\n",
        "\n",
        "\n",
        "# alternative manual installtation. note that it may take 30+ mins for building dependencies.\n",
        "# !pip3 install -U openmim\n",
        "# !mim install mmcv-full==1.7.0\n"
      ],
      "metadata": {
        "id": "t2lciBXyyuzA"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Start facechain WebUI service"
      ],
      "metadata": {
        "id": "OxDgRY8H4vta"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import os\n",
        "os.chdir('/content/facechain') # Note: replace with your facechain root\n",
        "print(os.getcwd())\n",
        "\n",
        "# Click on the gradio URL to start building your FaceChain digital-twin!\n",
        "!python3 app.py"
      ],
      "metadata": {
        "id": "NW5o0iiezTCg"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "Ghuyu_0Gx5XN"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}